package com.ynny.dao;

import com.ynny.bean.Scores;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class ScoresDaoImpl implements ISconresDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public List<Scores> selectAll() {
        String sql = "select * from scores";
        List<Scores> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Scores.class));

        return query;
    }

    @Override
    public Scores getScores(String number) {
        return null;
    }

    @Override
    public int insertScores(String newnumber, Integer newchinese, Integer newmath, Integer newenglish) {
        String sql = "insert into scores(number,chinese,math,english) values(?,?,?,?)";
        int update = jdbcTemplate.update(sql, newnumber, newchinese, newmath, newenglish);
        return update;
    }

    @Override
    public int updateScores(String number, Integer newMath) {
        return 0;
    }

    @Override
    public int updateScores(Integer newmath, String number) {
        String sql = "update scores set math = ? where number = ?";
        int update = jdbcTemplate.update(sql, newmath, number);
        return update;
    }

}
